require "Common/class"
require "Common/Base/BaseCtrl"
require "View/JoinRoomPanel"
--加入房间控制器
--create by lwt
--date 2018-4-23
JoinRoomCtrl = class("JoinRoomCtrl",BaseCtrl)

function JoinRoomCtrl:Awake(resName)
	self.curPanel = JoinRoomPanel.New("JoinRoomPanel")
	self.super:Awake(resName,self)
end

function JoinRoomCtrl:ShowPanel(data)
	self.super.ShowPanel(self,data)
end

function JoinRoomCtrl:InitCtrl()
	self.inputNum = {}
end

function JoinRoomCtrl:AddUIEvent()	
	for i=1,9 do
		self.luaBehaviour:AddClick(self.curPanel.numBtnList[i],function ()
			if ButtonHandle:ClickFastHand() then return end
			self:Click_Num(i)
		end)
	end
	self.luaBehaviour:AddClick(self.curPanel.numBtnList[10],function ()
		if ButtonHandle:ClickFastHand() then return end
		self:Click_Num(0)
	end)
	self.luaBehaviour:AddClick(self.curPanel.reInputBtn,function ()
		if ButtonHandle:ClickFastHand() then return end
		self:Click_ReInput()
	end)
	self.luaBehaviour:AddClick(self.curPanel.cancelBtn,function ()
		if ButtonHandle:ClickFastHand() then return end
		self:Click_Cancel()
	end)
	self.luaBehaviour:AddClick(self.curPanel.closeBtn,function ()
		if ButtonHandle:ClickFastHand() then return end
		self:ClosePanel()
	end)
end

function JoinRoomCtrl:AddListener()
	
end

function JoinRoomCtrl:RemoveListener()
	
end

function JoinRoomCtrl:Click_Num(idx)
	if #self.inputNum < 6 then
		table.insert(self.inputNum,idx)
	else
		return
	end
	self:SetInputNumString()
end

function JoinRoomCtrl:Click_ReInput()
	self.curPanel.roomNum.text = ""
	self.inputNum = {}
end


function JoinRoomCtrl:Click_Cancel()
	if #self.inputNum > 0 then
	table.remove(self.inputNum,#self.inputNum)
	else
		return
	end
	self:SetInputNumString()
end

function JoinRoomCtrl:SetInputNumString()
	self.curPanel.roomNum.text = ""
	for i=1,#self.inputNum do
		self.curPanel.roomNum.text = self.curPanel.roomNum.text..tostring(self.inputNum[i])
	end
end